Attribute VB_Name = "modFXRSTransactions"
'---------------------------------------------------------------------------------------
'Module : modFXRSTransactions
'Date   : 03/17/2004
'Author : Chris Elwell
'Purpose: Contains routines for building and sending FXRS transactions.
'
'2005-03-29, JFW, Adopt source version 720.3.1
'2005-03-29, JFW, Commodity tables field order 120, 414, 1030, 1275, 119.
'
'---------------------------------------------------------------------------------------
'
'---------------------------------------------------------------------------------------
' Module    : TransactionBuilder
' DateTime  : 8/03/2003
' Author    : Tim Johnson
' Modified  : Chris Elwell
' Mod Date  : 2/18/2004 - Field not added to transaction string if strFieldValue = ""
'             Also had to change FieldNumber data type from Int to String to allow for
'             multiple occurrence fields.
'             4/6/2004 - added line to remove double quotes from data.
' Purpose   : Function To Build Transactions - pass in a string variable, field number,
'             and data. The field and data are formatted and then the original
'             ByRef strTransactionString is modified.
'---------------------------------------------------------------------------------------
'
Public Function TransactionBuilder(ByRef strTransactionString As String, ByVal strFieldNumber As String, ByVal strFieldValue As String)
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:TransactionBuilder"
    
    If (strFieldNumber = "99" Or strFieldValue <> "") Then
        'Remove double qoutes from data
        strFieldValue = Replace(strFieldValue, Chr(34), "")
        strTransactionString = strTransactionString & strFieldNumber & "," & Chr(34) & strFieldValue & Chr(34)
    End If
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, g_strErrorLocation

End Function
'---------------------------------------------------------------------------------------
' Module    : TransactionParser
' DateTime  : 8/03/2003
' Author    : Tim Johnson
' Modified  : Chris Elwell
' Mod Date  : 8/26/2004 - added code to look for CRLF + "P1" + CRLF for the Eltron buffer
' Purpose   : Parse a field value from a transaction string
'---------------------------------------------------------------------------------------
'
Public Function TransactionParser(ByRef strTransaction As String, ByRef strFieldNumber As String)

    Dim strSearchChar As String     ' Field To Search For W/ Double Quotes
    Dim intStartPos As Integer      ' Field Value Start Position
    Dim intEndPos As Integer        ' Field Value End Position
    Dim intLen As Integer           ' Field Value Length
    Dim strError As String          ' Error string
    
    On Error GoTo EH
    
    'Set the string to search for
    If strFieldNumber = "0" Then
        strSearchChar = strFieldNumber & "," & Chr(34)
    Else
        strSearchChar = Chr(34) & strFieldNumber & "," & Chr(34)
    End If
    'Set the starting position
    intStartPos = InStr(1, strTransaction, strSearchChar, 1)
    ' If Field Not Found Return ""
    If intStartPos = 0 Then
        TransactionParser = ""
    Else
        'Eltron buffer contains double quotes so search for end characters
        If strFieldNumber = "188" Or strFieldNumber = "411" And InStr(1, strTransaction, vbCrLf + "P1" + vbCrLf) > 0 Then
            intStartPos = intStartPos + Len(strSearchChar)
            strSearchChar = vbCrLf + "P1" + vbCrLf
            intEndPos = InStr(intStartPos, strTransaction, strSearchChar, 1)
            intLen = intEndPos - intStartPos + 4
            TransactionParser = Mid(strTransaction, intStartPos, intLen) 'Final Field Value
        Else
            intStartPos = intStartPos + Len(strSearchChar)
            strSearchChar = Chr(34)
            intEndPos = InStr(intStartPos, strTransaction, strSearchChar, 1)
            intLen = intEndPos - intStartPos
            TransactionParser = Mid(strTransaction, intStartPos, intLen) 'Final Field Value
        End If
    End If
    
    Exit Function
EH:
    frmMain.NTService1.LogEvent svcMessageError, svcEventError, "[" & Err.number & "] " & Err.Description

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildCommonFlds
' DateTime  : 3/9/2004
' Modified  : 11/15/2004 Added Signature Required flag
' Author    : Chris Elwell
' Purpose   : Builds and returns the common fields for all transaction types.
'---------------------------------------------------------------------------------------
'
Public Function BuildCommonFlds() As String
    Dim strTrans As String
    Dim rsPreAssign As New ADODB.Recordset  'Used to lookup pre-assign trk#s
    Dim strQuery As String                  'Pre-assign query
    Dim i As Integer                        'Counter for pre-assign occurrence
    Dim strPreAssignKey As String
    
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildCommonFlds"
    
    'Build the FXRS transaction
    strTrans = ""
    TransactionBuilder strTrans, 0, "020"                            'Transaction type
    TransactionBuilder strTrans, 1, g_str1                           'Transaction ID

reQuery:
    'Added 3/2/05 for pre-assign
    
    App.LogEvent "Test, PreAssign, BuildCommonFlds, select for f1 `" & g_str1 & "`"
    
    strQuery = "SELECT * FROM PreAssign WHERE f1 = '" & g_str1 & "'"
    rsPreAssign.Open strQuery, g_connFSMSClient, adOpenStatic, adLockBatchOptimistic
    strPreAssignKey = g_str1
    
    '2005-05-27, JFW, P&W
    If rsPreAssign.EOF And g_str1222 <> "" Then
        
        rsPreAssign.Close
        strQuery = "SELECT * FROM PreAssign WHERE f1 = '" & g_str1222 & "'"
        rsPreAssign.Open strQuery, g_connFSMSClient, adOpenStatic, adLockBatchOptimistic
        strPreAssignKey = g_str1222
    
        App.LogEvent "Test, PreAssign, BuildCommonFlds, strPreAssignKey " & strPreAssignKey
        
    Else
    
        App.LogEvent "Test, PreAssign, BuildCommonFlds, no preassign"
    
    End If
        
    If g_str1274 = "92" Or g_str1274 = "90" Then
        If Not rsPreAssign.EOF Then
            Do Until rsPreAssign.EOF
                rsPreAssign.MoveNext
            Loop
            rsPreAssign.MoveFirst
        End If
        
        If Not rsPreAssign.EOF Then
            If CLng(g_str116) > rsPreAssign.RecordCount Then
                Call frmPreAssign.MakePreAssign(strPreAssignKey, CLng(g_str116) - rsPreAssign.RecordCount, "ground")
                rsPreAssign.Close
                GoTo reQuery
            End If
        End If
    End If
    
    'Loop through pre-assign recordset and add fields
    i = 1
    
    App.LogEvent "Test, PreAssign, BuildCommonFlds, transaction start"
    
    Do Until rsPreAssign.EOF
    
        App.LogEvent "Test, PreAssign, BuildCommonFlds, transaction `" & "1222-" & Trim(Str(i)) & "," & rsPreAssign!f29 & "`"
        
        TransactionBuilder strTrans, "1221-" & Trim(Str(i)), "Y"                       'Preassign flag
        TransactionBuilder strTrans, "1222-" & Trim(Str(i)), rsPreAssign!f29           'Trk# for preassign
        Select Case rsPreAssign!Type
            Case "Express US Domestic"
                TransactionBuilder strTrans, "1223-" & Trim(Str(i)), "0201"           'Form ID
            Case "Express Intl Master"
                TransactionBuilder strTrans, "1223-" & Trim(Str(i)), "0430"           'Form ID
            Case "Express Intl MPS"
                TransactionBuilder strTrans, "1223-" & Trim(Str(i)), "0441"           'Form ID
            Case "Express COD Master"
                TransactionBuilder strTrans, "1223-" & Trim(Str(i)), "0301"           'Form ID
            Case "Express COD MPS"
                TransactionBuilder strTrans, "1223-" & Trim(Str(i)), "0261"           'Form ID
            Case "Canada"
                TransactionBuilder strTrans, "1223-" & Trim(Str(i)), "0451"           'Form ID
        End Select
        TransactionBuilder strTrans, 1224, rsPreAssign!f28           'COD Return Trk# for preassign
        TransactionBuilder strTrans, 1225, rsPreAssign!f527          'COD Return Form ID for preassign
        
        rsPreAssign.MoveNext
        i = i + 1
    Loop
    
    App.LogEvent "Test, PreAssign, BuildCommonFlds, transaction " & strTrans

    ' 2007-12-14, JFW, Ground preassign requires specification for each piece.
    'For i = i To CLng(g_str116)
    '    TransactionBuilder strTrans, "1221-" & Trim(Str(i)), "N"                       'Remaining pieces do not have preassign
    'Next i
    
    TransactionBuilder strTrans, 50, g_str50                         'Country - 2 character code
    TransactionBuilder strTrans, 12, g_str12                         'Recipient Contact
    TransactionBuilder strTrans, 11, g_str11                         'Recipient Company Name
    TransactionBuilder strTrans, 13, g_str13                         'Recipient Addr1
    TransactionBuilder strTrans, 14, g_str14                         'Recipient Addr2
    TransactionBuilder strTrans, 15, g_str15                         'Recipient City
    TransactionBuilder strTrans, 16, g_str16                         'Recipient State
    TransactionBuilder strTrans, 17, g_str17                         'Recipient Zip
    TransactionBuilder strTrans, 18, g_str18                         'Phone - Using shipper phone
    TransactionBuilder strTrans, 440, g_str440                       'Residential flag
    TransactionBuilder strTrans, 32, g_str32                                            'Shipper Contact Name
    TransactionBuilder strTrans, 4, g_str4                                              'Shipper Company Name
    TransactionBuilder strTrans, 5, g_str5                                              'Shipper Addr1
    TransactionBuilder strTrans, 6, g_str6                                              'Shipper Addr2
    TransactionBuilder strTrans, 7, g_str7                                              'Shipper City
    TransactionBuilder strTrans, 8, g_str8                                              'Shipper State
    TransactionBuilder strTrans, 9, g_str9                                              'Shipper Zip
    TransactionBuilder strTrans, 183, g_str183                                          'Shipper Phone
    TransactionBuilder strTrans, 1670, RemoveSpecial(ImpliedDecimal(g_str1670))         'Weight
    TransactionBuilder strTrans, 1274, g_str1274                                        'Service Type
    TransactionBuilder strTrans, 1273, g_str1273                                        'Packaging Type
    TransactionBuilder strTrans, 1958, "BOX"                                            'FXRS0760 new Packaging Type
    TransactionBuilder strTrans, 24, g_str24                                            'Ship Date Note yyyymmdd format, no punctuation
    ' 2007-11-30, JFW, Causes ground trans to fail on v.801
    If g_str1274 <> "92" And g_str1274 <> "90" Then
        TransactionBuilder strTrans, 68, g_str68                                            'Currency Type
    End If
    TransactionBuilder strTrans, 1090, g_str1090                                        'Rate Currency
    TransactionBuilder strTrans, 23, g_str23                                            'Pay Type
    TransactionBuilder strTrans, 20, g_str20                                            'Bill-To Acct#
    TransactionBuilder strTrans, 25, g_str25                                            'References
    TransactionBuilder strTrans, 3056, g_str3056                                        'P.O. Number
    TransactionBuilder strTrans, 3057, g_str3057                                        'Invoice Number
    TransactionBuilder strTrans, 38, g_str38                                            'Department Notes
    TransactionBuilder strTrans, 26, Trim(Str(CLng(Val(g_str26))))                      'Declared Value
    TransactionBuilder strTrans, 57, g_str57                        'DIM H
    TransactionBuilder strTrans, 58, g_str58                        'DIM W
    TransactionBuilder strTrans, 59, g_str59                        'DIM L
    'Special Svcs
    If g_str1332 = "Y" Then
        TransactionBuilder strTrans, 1332, g_str1332                                    'Alcohol Flag
        TransactionBuilder strTrans, 40, g_str40                                        'Alcohol Contents
        TransactionBuilder strTrans, 41, g_str41                                        'Alcohol Packaging
        TransactionBuilder strTrans, 42, RemoveSpecial(ImpliedDecimal(g_str42, 3))      'Alcohol Volume
        TransactionBuilder strTrans, 52, g_str52                                        'Alcohol Quantity
    End If
    'Added 8/6 And g_blnCODFirstPiece for MPS Ground COD 1st Piece
    If g_str27 = "Y" Then
        If g_str3014 = "Y" And g_str1274 = "92" Then
            TransactionBuilder strTrans, 3014, g_str3014            'ECOD Flag
        Else
            TransactionBuilder strTrans, 27, g_str27                'COD Flag
        End If
        TransactionBuilder strTrans, 53, RemoveSpecial(ImpliedDecimal(g_str53))                    'COD Amount
        If g_str1274 <> "92" Then
            TransactionBuilder strTrans, 54, g_str54                'COD Cashier Chk or MO
        Else
            TransactionBuilder strTrans, 3000, g_str3000            'COD Ground payment type
        End If
        TransactionBuilder strTrans, 186, g_str186                  'COD Add Freight Chgs
        TransactionBuilder strTrans, 439, g_str439                  'COD Remit Payer
        TransactionBuilder strTrans, 1237, g_str1237                'COD Return Phone
        TransactionBuilder strTrans, 1238, g_str1238                'COD Return Company
        TransactionBuilder strTrans, 1240, g_str1240                'COD Return Addr1
        TransactionBuilder strTrans, 1241, g_str1241                'COD Return Addr2
        TransactionBuilder strTrans, 1242, g_str1242                'COD Return City
        TransactionBuilder strTrans, 1243, g_str1243                'COD Return State
        TransactionBuilder strTrans, 1244, g_str1244                'COD Return Zip
    End If
    If g_str51 = "Y" Then
        TransactionBuilder strTrans, 51, g_str51                    'Sig Rel Flag
        TransactionBuilder strTrans, 1118, g_str1118                'Sig Rel #
    End If
    If g_str1268 = "Y" Then
        TransactionBuilder strTrans, 1268, g_str1268                                    'Dry Ice Flag
        TransactionBuilder strTrans, 1684, RemoveSpecial(ImpliedDecimal(g_str1684))     'Dry Ice Wgt
    End If
    If g_str1200 = "Y" Then                                         'HAL
        TransactionBuilder strTrans, 1200, g_str1200                'HAL Flag
        TransactionBuilder strTrans, 44, g_str44                    'HAL Station Address
        TransactionBuilder strTrans, 46, g_str46                    'HAL City
        If g_str47 = "" Then
            TransactionBuilder strTrans, 47, g_str16                    'HAL State
        Else
            TransactionBuilder strTrans, 47, g_str47                    'HAL State
        End If
        TransactionBuilder strTrans, 48, g_str48                    'HAL Postal Code
        TransactionBuilder strTrans, 49, g_str49                    'HAL Phone Number
    End If
    If g_str1274 = "90" Or g_str1274 = "92" Then
        TransactionBuilder strTrans, 3008, g_str3008                'Auto POD
        TransactionBuilder strTrans, 3009, g_str3009                'AOD
        TransactionBuilder strTrans, 3018, g_str3018                'Non-Standard Packaging
    End If
    If g_str1266 = "Y" Then
        TransactionBuilder strTrans, 1266, g_str1266                'Sat Del
    End If
    If g_str1274 = "90" Then
        TransactionBuilder strTrans, 3019, g_str3019                'FHD Signature Svc
        TransactionBuilder strTrans, 3020, g_str3020                'FHD Special Svcs
        TransactionBuilder strTrans, 3023, g_str3023                'FHD Special Svcs
        TransactionBuilder strTrans, 3024, g_str3024                'FHD Special Svcs
    End If
    'Add Email addresses only if Email Alerts checkbox checked
    If frmShip.chkEmailAlert = 1 Then
        If g_str1274 <> "90" And g_str1274 <> "92" Then
            TransactionBuilder strTrans, 1201, g_str1201                'Shipper Email Address
            TransactionBuilder strTrans, 1202, g_str1202                'Recipient Email Address
            TransactionBuilder strTrans, "1204-1", g_str1204_1          'Other Email Address 1
            TransactionBuilder strTrans, "1204-2", g_str1204_2          'Other Email Address 2
            TransactionBuilder strTrans, "1204-3", g_str1204_3          'Other Email Address 3
            TransactionBuilder strTrans, "1206-1", g_str1206_1          'Other Ship Alert Flag 1
            TransactionBuilder strTrans, "1206-2", g_str1206_2          'Other Ship Alert Flag 2
            TransactionBuilder strTrans, "1206-3", g_str1206_3          'Other Ship Alert Flag 3
            TransactionBuilder strTrans, "1551-1", g_str1551_1          'Other Delivery Notification Flag 1
            TransactionBuilder strTrans, "1551-2", g_str1551_2          'Other Delivery Notification Flag 2"
            TransactionBuilder strTrans, "1551-3", g_str1551_3          'Other Delivery Notification Flag 3"
            TransactionBuilder strTrans, 1553, g_str1553                'Shipper Delivery Notification Flag"
            TransactionBuilder strTrans, 1554, g_str1554                'Shipper Ship Alert Flag"
            TransactionBuilder strTrans, 1556, g_str1556                'Recipient Delivery Notification Flag"
            TransactionBuilder strTrans, 1557, g_str1557                'Recipient Ship Alert Flag"
        Else
            TransactionBuilder strTrans, 1202, g_str1202                'Recipient Email Address
            TransactionBuilder strTrans, 1557, g_str1557                'Recipient Ship Alert Flag"
        End If
    End If
    
    TransactionBuilder strTrans, 187, g_str187                          'Label Type
    TransactionBuilder strTrans, 1660, g_str1660                        'Custom label flag
    TransactionBuilder strTrans, 537, g_str537                          'Thermal/Laser Label prt UNC/File Path
    
    'Don't send field 1282 if label type is laser (DIB)
    If g_str187 <> "DIB" And g_str187 <> "PNG" Then
        TransactionBuilder strTrans, 1282, g_str1282                    'Printer Type Indicator
    End If
    
    TransactionBuilder strTrans, 10, g_str10                            'Acct Number
    TransactionBuilder strTrans, 498, g_str498                      'Meter
    'Add flag and Shipper Country for return label
    If g_str2382 = "2" Then
        TransactionBuilder strTrans, 2382, g_str2382                    'Create Ground Return label
        TransactionBuilder strTrans, 117, "US"                          'Shipper Country
    End If

    'Add handling charge fields for use with doc-tab
    With frmSetup
        If .chkAddHndlChg = 1 Then
            If .f1588(1) Then
                TransactionBuilder strTrans, 1588, "1"                  'Handling charge Type - flat amount
            ElseIf .f1588(2) Then
                TransactionBuilder strTrans, 1588, "2"                  'Handling charge Type - % of freight chg
            ElseIf .f1588(3) Then
                TransactionBuilder strTrans, 1588, "3"                  'Handling charge Type - % of Net chg
            End If
            'Handling chg application point
            If .f1606(0) Then
                TransactionBuilder strTrans, 1606, "0"                  'Apply to pkg
            ElseIf .f1606(1) Then
                TransactionBuilder strTrans, 1606, "1"                  'Apply to shipment
            End If
            
            If .chkBySvc = 0 Then
                TransactionBuilder strTrans, 1595, RemoveSpecial(ImpliedDecimal(.f1595(1)))            'All services have same handling chg
            Else
                Select Case g_str1274
                    Case "01"
                        TransactionBuilder strTrans, 1595, RemoveSpecial(.f1595(1))        'PO amount
                    Case "05"
                        TransactionBuilder strTrans, 1595, RemoveSpecial(.f1595(2))        'SO amount
                    Case "03"
                        TransactionBuilder strTrans, 1595, RemoveSpecial(.f1595(3))        'ES amount
                    Case "20"
                        TransactionBuilder strTrans, 1595, RemoveSpecial(.f1595(4))        'XS amount
                    Case "92"
                        TransactionBuilder strTrans, 1595, RemoveSpecial(.f1595(5))        'GR amount
                    Case "90"
                        TransactionBuilder strTrans, 1595, RemoveSpecial(.f1595(6))        'HD amount
                End Select
            End If
        End If
    End With
    
    'Signature Required
    TransactionBuilder strTrans, 1208, g_str1208            'Signature Required flag
    
    'Alt Return Addr fields
    If g_str1586 = "Y" Then
        TransactionBuilder strTrans, 1586, g_str1586        'Print Alt Return flag
        TransactionBuilder strTrans, 1485, g_str1485        'Alt Return Contact
        TransactionBuilder strTrans, 1486, g_str1486        'Alt Return Company
        TransactionBuilder strTrans, 1487, g_str1487        'Alt Return Addr1
        TransactionBuilder strTrans, 1488, g_str1488        'Alt Return Addr2
        TransactionBuilder strTrans, 1489, g_str1489        'Alt Return City
        TransactionBuilder strTrans, 1490, g_str1490        'Alt Return State
        TransactionBuilder strTrans, 1491, g_str1491        'Alt Return Zip
        TransactionBuilder strTrans, 1492, g_str1492        'Alt Return Phone
        TransactionBuilder strTrans, 1585, g_str1585        'Alt Return Country
    End If
    
    'Add custom doc-tab fields
    TransactionBuilder strTrans, 581, g_str581              'Custom Doc-Tab1
    TransactionBuilder strTrans, 582, g_str582              'Custom Doc-Tab2
    TransactionBuilder strTrans, 583, g_str583              'Custom Doc-Tab3
    TransactionBuilder strTrans, 584, g_str584              'Custom Doc-Tab4
    TransactionBuilder strTrans, 585, g_str585              'Custom Doc-Tab5
    TransactionBuilder strTrans, 586, g_str586              'Custom Doc-Tab6
    TransactionBuilder strTrans, 587, g_str587              'Custom Doc-Tab7
    TransactionBuilder strTrans, 588, g_str588              'Custom Doc-Tab8
    TransactionBuilder strTrans, 589, g_str589              'Custom Doc-Tab9
    TransactionBuilder strTrans, 590, g_str590              'Custom Doc-Tab10
    TransactionBuilder strTrans, 591, g_str591              'Custom Doc-Tab11
    TransactionBuilder strTrans, 592, g_str592              'Custom Doc-Tab12
    
    BuildCommonFlds = strTrans

    Exit Function
EH:
     MsgBox Err.Description, vbCritical, g_strErrorLocation

End Function

'---------------------------------------------------------------------------------------
' Module    : BuildDomShipTrans
' DateTime  : 2/18/2004
' Author    : Chris Elwell
' Purpose   : Builds and returns the transaction string for Domestic shipping
'---------------------------------------------------------------------------------------
'
Public Function BuildDomShipTrans() As String
    Dim strTrans As String

    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildDomShipTrans"
    
    'Build the FXRS transaction
    strTrans = BuildCommonFlds
    TransactionBuilder strTrans, 99, ""                             'End of Transaction
    
    BuildDomShipTrans = strTrans

    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildIntlMPSShipTrans
' DateTime  : 3/08/2004
' Modified  : 2/24/2005 - Modified code to use MPS form or main screen
' Author    : Chris Elwell
' Purpose   : Builds and returns the transaction string for MPS Intl
'---------------------------------------------------------------------------------------
'
Public Function BuildIntlMPSShipTrans(ByVal strOrderNum As String) As String
    Dim strTrans As String
    Dim strQuery As String
    Dim rsCommodity As New ADODB.Recordset
    Dim i As Integer
    Dim rsIntlMPS As New ADODB.Recordset
    
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildIntlMPSShipTrans"
    
    strQuery = "SELECT * FROM IntlCommodities WHERE f1 = '" & strOrderNum & "'"
    rsCommodity.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    
    'Build the common fields
    strTrans = BuildCommonFlds
    
    'Loop through Intl DIMs
    i = 1
    
    strQuery = "SELECT * FROM MPS WHERE f1 = '" & strOrderNum & "'"
    rsIntlMPS.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    'If using the MPS form get values from recordset
    If rsIntlMPS.RecordCount > 0 Then
        Do Until rsIntlMPS.EOF
            TransactionBuilder strTrans, "57-" & Trim(Str(i)), rsIntlMPS("g_str57") & ""            'CI Freight Charge
            TransactionBuilder strTrans, "58-" & Trim(Str(i)), rsIntlMPS("g_str58") & ""            'CI Insurance Charge
            TransactionBuilder strTrans, "59-" & Trim(Str(i)), rsIntlMPS("g_str59") & ""            'CI Other Charge
            TransactionBuilder strTrans, "1670-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsIntlMPS("g_str1670"))) & ""
            TransactionBuilder strTrans, "25-" & Trim(Str(i)), rsIntlMPS("g_str25") & ""            'References
            TransactionBuilder strTrans, "3056-" & Trim(Str(i)), rsIntlMPS("g_str3056") & ""        'P.O. #
            TransactionBuilder strTrans, "3057-" & Trim(Str(i)), rsIntlMPS("g_str3057") & ""        'Inv #
        
            'Total Declared Value
            g_str26 = Str(Val(g_str26) + Val(rsIntlMPS!g_str26 & ""))
            
            If rsIntlMPS("g_str3018") = 1 Then
                 TransactionBuilder strTrans, "3018-" & Trim(Str(i)), "Y"                        'Non-standard pkging
            End If
            i = i + 1
            rsIntlMPS.MoveNext
        Loop
        TransactionBuilder strTrans, 26, Trim(Str(CLng(Val(g_str26))))       'Carriage Value
    'Else get values from main form
    Else
        TransactionBuilder strTrans, 116, g_str116                          '# of Pkgs
    End If
    
    TransactionBuilder strTrans, 1116, g_str1116            'DIM Units
    'Build the Intl MPS fields
    TransactionBuilder strTrans, 1349, g_str1349            'AES Filing Status
    TransactionBuilder strTrans, 1352, g_str1352            'Sender ID Type
    TransactionBuilder strTrans, 1139, g_str1139            'Sender IRS/EIN
    TransactionBuilder strTrans, 70, g_str70                'Duty/Tax Pay Type
    TransactionBuilder strTrans, 71, g_str71                'Duty/Tax Acct#
    TransactionBuilder strTrans, 73, g_str73                'Parties Related Flag
    TransactionBuilder strTrans, 74, g_str74                'Country of Ultimate Dest
    TransactionBuilder strTrans, 75, g_str75                'Weight type
    'Added 3/18/05 to pass IRS/EIN for CA
    If g_str117 = "CA" Then
        TransactionBuilder strTrans, 118, g_str118          'IRS/EIN #
    Else
        TransactionBuilder strTrans, 1358, g_str1358        'FTSR Exemption #
    End If
    
    TransactionBuilder strTrans, 413, g_str413              'NAFTA Flag
    'Loop through commodities
    i = 1
    g_str119 = "0"
    Do While Not rsCommodity.EOF
        TransactionBuilder strTrans, "77-" & Trim(Str(i)), RemoveSpecial(rsCommodity("g_str77")) & ""           'Terms of Sale
        TransactionBuilder strTrans, "79-" & Trim(Str(i)), rsCommodity("g_str79") & ""                          'Description
        TransactionBuilder strTrans, "80-" & Trim(Str(i)), rsCommodity("g_str80") & ""                          'Country of Manu
        TransactionBuilder strTrans, "81-" & Trim(Str(i)), rsCommodity("g_str81") & ""                          'Harmonized Code
        TransactionBuilder strTrans, "82-" & Trim(Str(i)), rsCommodity("g_str82") & ""                          'Quantity
        TransactionBuilder strTrans, "83-" & Trim(Str(i)), rsCommodity("g_str83") & ""                          'Export license #
        TransactionBuilder strTrans, "84-" & Trim(Str(i)), Format(rsCommodity("g_str84"), "YYYYMMDD") & ""      'Export license Exp Date
        TransactionBuilder strTrans, "120-" & Trim(Str(i)), rsCommodity("g_str120") & ""                        'Marks and Numbers, 2005-03-29, JFW
        TransactionBuilder strTrans, "414-" & Trim(Str(i)), rsCommodity("g_str414") & ""                        'Unit of Measure
        TransactionBuilder strTrans, "1030-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsCommodity("g_str1030"), 6)) & ""       'Commodity Unit Value
        TransactionBuilder strTrans, "1275-" & Trim(Str(i)), rsCommodity("g_str1275") & ""                        'Part number
        'Add the Customs values of the individual commodities for a total
        g_str119 = Str(Val(g_str119) + Val(rsCommodity("g_str119"))) & ""
        i = i + 1
        rsCommodity.MoveNext
    Loop
    TransactionBuilder strTrans, 119, RemoveSpecial(ImpliedDecimal(g_str119))  'Total Customs value of shipment
    
    If g_str113 = "Y" Then
        TransactionBuilder strTrans, 113, g_str113                                  'CI Flag
        TransactionBuilder strTrans, 72, g_str72                                    'Terms of Sale
        TransactionBuilder strTrans, 532, RemoveSpecial(ImpliedDecimal(g_str532))   'CI Freight Charge
        TransactionBuilder strTrans, 533, RemoveSpecial(ImpliedDecimal(g_str533))   'CI Insurance Charge
        TransactionBuilder strTrans, 534, RemoveSpecial(ImpliedDecimal(g_str534))   'CI Other Charge
        TransactionBuilder strTrans, 1357, g_str1357                                'CI Other Chg Type
        TransactionBuilder strTrans, "418-1", g_str418_1                            'CI Comment 1
        TransactionBuilder strTrans, "418-2", g_str418_2                            'CI Comment 2
        TransactionBuilder strTrans, "418-3", g_str418_3                            'CI Comment 3
        TransactionBuilder strTrans, 538, g_str538                                  'CI Printer UNC
    Else
        TransactionBuilder strTrans, 113, "N"                                       'CI Flag
    End If
    
    If g_str1174 = "Y" Then
        TransactionBuilder strTrans, 1174, g_str1174        'BSO Flag
        TransactionBuilder strTrans, 66, g_str66            'Broker Name
        TransactionBuilder strTrans, 67, g_str67            'Broker Phone
        TransactionBuilder strTrans, 1179, g_str1179        'Broker Acct#
        TransactionBuilder strTrans, 1180, g_str1180        'Broker Company
        TransactionBuilder strTrans, 1181, g_str1181        'Broker Addr1
        TransactionBuilder strTrans, 1182, g_str1182        'Broker Addr2
        TransactionBuilder strTrans, 1183, g_str1183        'Broker City
        TransactionBuilder strTrans, 1184, g_str1184        'Broker St/Prov
        TransactionBuilder strTrans, 1185, g_str1185        'Broker POstal Code
        TransactionBuilder strTrans, 1186, g_str1186        'Broker Country
        TransactionBuilder strTrans, 1187, g_str1187        'Broker ID
        TransactionBuilder strTrans, 1343, g_str1343        'Broker Email
        TransactionBuilder strTrans, 1344, g_str1344        'Broker Fax#
        TransactionBuilder strTrans, 1345, g_str1345        'Broker Pager #
    End If
    
    
    If frmShip.chkIOR Then
        TransactionBuilder strTrans, 168, g_str168        'IOR ID
        TransactionBuilder strTrans, 169, g_str169        'IOR Country
        TransactionBuilder strTrans, 170, g_str170            'IOR Name
        TransactionBuilder strTrans, 171, g_str171            'IOR Company
        TransactionBuilder strTrans, 172, g_str172        'IOR Addr1
        TransactionBuilder strTrans, 173, g_str173        'IOR Addr2
        TransactionBuilder strTrans, 174, g_str174        'IOR City
        TransactionBuilder strTrans, 175, g_str175        'IOR St/Prov
        TransactionBuilder strTrans, 176, g_str176        'IOR POstal Code
        TransactionBuilder strTrans, 177, g_str177        'IOR Account
        TransactionBuilder strTrans, 178, g_str178        'IOR Phone
        TransactionBuilder strTrans, 180, g_str180        'IOR Tax ID
    End If
    
    'Added 3/3/05 for CA Export
    If g_str117 = "CA" Then
        If frmShip.chkB13A = 1 Then
            TransactionBuilder strTrans, 1651, g_str1651        'B13A Filing Options
            TransactionBuilder strTrans, 1652, g_str1652        'Export Statement Data
            TransactionBuilder strTrans, 1653, g_str1653        'Export Permit #
        Else
            TransactionBuilder strTrans, 1651, "1"              'B13A Filing Options
            ' 2007-08-17, JFW, Export permit on Intl screen
            If g_str1653 <> "" Then
                TransactionBuilder strTrans, 1653, g_str1653        'Export Permit #
            End If
        End If
    End If
    
    TransactionBuilder strTrans, 99, ""                             'End of Transaction
    
    BuildIntlMPSShipTrans = strTrans

Release:
    If rsCommodity.State = adStateOpen Then
        rsCommodity.Close
    End If
    Set rsCommodity = Nothing
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation
    Resume Release
    
End Function
'---------------------------------------------------------------------------------------
' Module    : BuildDomMPSShipTrans
' DateTime  : 3/18/2004
' Modified  : 8/6/2004, 2/8/2005
' Author    : Chris Elwell
' Purpose   : Builds and returns the transaction string for Ground MPS
'             8/6/2004 added to code for MPS COD on First Piece
'             2/8/2005 changed DV to multiple occurrence fields
'---------------------------------------------------------------------------------------
'
Public Function BuildDomMPSShipTrans(ByVal strOrderNum As String) As String
    Dim strTrans As String
    Dim strQuery As String
    Dim rsDomMPS As New ADODB.Recordset
    Dim i As Integer
    
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildDomMPSShipTrans"
    
    strQuery = "SELECT * FROM MPS WHERE f1 = '" & strOrderNum & "'"
    rsDomMPS.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    
    'Build the common fields
    strTrans = BuildCommonFlds
    
    'Added 8/6 to skip the first record in a Ground MPS COD on First Piece
    If g_blnCODNextPiece Then
        rsDomMPS.MoveNext
    End If
    
    'Loop through Dom MPS fields
    i = 1
    Do While Not rsDomMPS.EOF
        
        TransactionBuilder strTrans, "1670-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsDomMPS("g_str1670")))
        TransactionBuilder strTrans, "26-" & Trim(Str(i)), rsDomMPS("g_str26") & ""         'Declared Value
        TransactionBuilder strTrans, "57-" & Trim(Str(i)), rsDomMPS("g_str57") & ""         'DIM
        TransactionBuilder strTrans, "58-" & Trim(Str(i)), rsDomMPS("g_str58") & ""         'DIM
        TransactionBuilder strTrans, "59-" & Trim(Str(i)), rsDomMPS("g_str59") & ""         'DIM
        TransactionBuilder strTrans, "25-" & Trim(Str(i)), g_str25                          'References
        TransactionBuilder strTrans, "3056-" & Trim(Str(i)), g_str3056                      'P.O. #
        TransactionBuilder strTrans, "3057-" & Trim(Str(i)), g_str3057                      'Inv #
        
        If rsDomMPS("g_str3018") = 1 Then
            TransactionBuilder strTrans, "3018-" & Trim(Str(i)), "Y"                        'Non-standard pkging
        End If
        
        i = i + 1
        rsDomMPS.MoveNext
    Loop
    
    'Add end of transaction string
    TransactionBuilder strTrans, 99, ""                                                     'End of Transaction
    
    'Return transaction string
    BuildDomMPSShipTrans = strTrans
    
Release:
    If rsDomMPS.State = adStateOpen Then
        rsDomMPS.Close
    End If
    Set rsDomMPS = Nothing
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation
    Resume Release

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildCODFirstPieceShipTrans
' DateTime  : 8/6/2004
' Author    : Chris Elwell
' Purpose   : Builds and returns the transaction string for Ground COD MPS, but doing COD
'             only on the first package.
'---------------------------------------------------------------------------------------
'
Public Function BuildCODFirstPieceShipTrans(ByVal strOrderNum As String) As String
    Dim strTrans As String
    Dim strQuery As String
    Dim rsDomMPS As New ADODB.Recordset
    Dim i As Integer
    
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildCODFirstPieceShipTrans"
    
    strQuery = "SELECT * FROM MPS WHERE f1 = '" & strOrderNum & "'"
    rsDomMPS.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    
    'Build the common fields
    strTrans = BuildCommonFlds
    
    'If Dec Val is blank on main screen get value in MPS table
    If g_str26 = "" Then
        TransactionBuilder strTrans, 26, rsDomMPS("g_str26") & ""
    Else
        TransactionBuilder strTrans, 26, Trim(Str(CLng(Val(g_str26))))              'Declared Value
    End If
    
    TransactionBuilder strTrans, 1670, RemoveSpecial(ImpliedDecimal(rsDomMPS("g_str1670")))
    TransactionBuilder strTrans, 57, rsDomMPS("g_str57") & ""          'DIM
    TransactionBuilder strTrans, 58, rsDomMPS("g_str58") & ""          'DIM
    TransactionBuilder strTrans, 59, rsDomMPS("g_str59") & ""          'DIM
    TransactionBuilder strTrans, 25, rsDomMPS("g_str25") & ""          'References
    TransactionBuilder strTrans, 3056, rsDomMPS("g_str3056") & ""      'P.O. #
    TransactionBuilder strTrans, 3057, rsDomMPS("g_str3057") & ""      'Inv #
    If rsDomMPS("g_str3018") = 1 Then
        TransactionBuilder strTrans, 3018, "Y"                          'Non-standard pkging
    End If
    
    g_str25 = rsDomMPS("g_str25") & ""
    g_str3056 = rsDomMPS("g_str3056") & ""
    g_str3057 = rsDomMPS("g_str3057") & ""
        
    'Add end of transaction string
    TransactionBuilder strTrans, 99, ""                             'End of Transaction
    'Return transaction string
    BuildCODFirstPieceShipTrans = strTrans
    
Release:
    If rsDomMPS.State = adStateOpen Then
        rsDomMPS.Close
    End If
    Set rsDomMPS = Nothing
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation
    Resume Release

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildIntlDocShipTrans
' DateTime  : 3/18/2004
' Author    : Chris Elwell
' Purpose   : Builds and returns the transaction string for Intl documents
'---------------------------------------------------------------------------------------
'
Public Function BuildIntlDocShipTrans()
    Dim strTrans As String
    
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildIntlDocShipTrans"
    
    'Build the common fields
    strTrans = BuildCommonFlds
    'Add Intl document fields
    TransactionBuilder strTrans, 74, g_str74                'Country of Ultimate Dest
    TransactionBuilder strTrans, 75, g_str75                'Weight type
    TransactionBuilder strTrans, 79, g_str79                'Description
    TransactionBuilder strTrans, 80, g_str80                'Country of Manufacture
    If g_str26 = "" Then g_str26 = "0"
    'Set Doc Customs Value = to value in f26 X 100
    TransactionBuilder strTrans, 119, Trim(Str(Val(g_str26) * 100))      'Customs Value
    TransactionBuilder strTrans, 1349, g_str1349            'AES Filing Status
    TransactionBuilder strTrans, 1352, g_str1352            'Sender ID Type
    TransactionBuilder strTrans, 1139, g_str1139            'Sender IRS/EIN
    TransactionBuilder strTrans, 99, ""                     'End of Transaction

    BuildIntlDocShipTrans = strTrans
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, g_strErrorLocation
    
End Function
'---------------------------------------------------------------------------------------
' Module    : BuildCADomShipTrans
' DateTime  : 1/27/2005
' Author    : Chris Elwell
' Purpose   : Builds and returns the transaction string for Intra-CA shipping
'---------------------------------------------------------------------------------------
'
Public Function BuildCADomShipTrans() As String
    Dim strTrans As String

    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildCADomShipTrans"
    
    'Build the FXRS transaction
    strTrans = BuildCommonFlds
    TransactionBuilder strTrans, 116, g_str116                      '# pkgs
    TransactionBuilder strTrans, 75, g_str75                        'wgt type
    TransactionBuilder strTrans, 26, Trim(Str(CLng(Val(g_str26))))               'Declared Value
    TransactionBuilder strTrans, 57, g_str57                        'DIM H
    TransactionBuilder strTrans, 58, g_str58                        'DIM W
    TransactionBuilder strTrans, 59, g_str59                        'DIM L
    TransactionBuilder strTrans, 99, ""                             'End of Transaction
    
    BuildCADomShipTrans = strTrans

    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildReturnLabel
' DateTime  : 7/26/2004
' Author    : Chris Elwell
' Purpose   : Builds and returns the fields required for a Ground Return Label.
'---------------------------------------------------------------------------------------
'
Public Function BuildReturnLabel() As String
    Dim strTrans As String

    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildReturnLabel"
    
    'Build the FXRS transaction *** REVERSE SHIPPER AND RECIPIENT FIELDS
    strTrans = ""
    TransactionBuilder strTrans, 0, "020"                           'Transaction type
    TransactionBuilder strTrans, 1, g_str1                          'Transaction ID
    TransactionBuilder strTrans, 50, g_str50                        'Country - 2 character code
    TransactionBuilder strTrans, 32, g_str12                        'Recipient Contact
    TransactionBuilder strTrans, 4, g_str11                         'Recipient Company Name
    TransactionBuilder strTrans, 5, g_str13                         'Recipient Addr1
    TransactionBuilder strTrans, 6, g_str14                         'Recipient Addr2
    TransactionBuilder strTrans, 7, g_str15                         'Recipient City
    TransactionBuilder strTrans, 8, g_str16                         'Recipient State
    TransactionBuilder strTrans, 9, g_str17                         'Recipient Zip
    TransactionBuilder strTrans, 183, g_str18                       'Phone - Using shipper phone
    TransactionBuilder strTrans, 12, g_str32                        'Shipper Contact Name
    TransactionBuilder strTrans, 11, g_str4                         'Shipper Company Name
    TransactionBuilder strTrans, 13, g_str5                         'Shipper Addr1
    TransactionBuilder strTrans, 14, g_str6                         'Shipper Addr2
    TransactionBuilder strTrans, 15, g_str7                         'Shipper City
    TransactionBuilder strTrans, 16, g_str8                         'Shipper State
    TransactionBuilder strTrans, 17, g_str9                         'Shipper Zip
    TransactionBuilder strTrans, 18, g_str183                       'Shipper Phone
    TransactionBuilder strTrans, 23, g_str23                                            'Pay Type
    TransactionBuilder strTrans, 20, g_str20                                            'Bill-To Acct#
    TransactionBuilder strTrans, 1670, RemoveSpecial(ImpliedDecimal(g_str1670))         'Weight                              'Weight
    TransactionBuilder strTrans, 1274, "92"                                             'Service Type
    TransactionBuilder strTrans, 1273, "01"                                             'Packaging Type
    TransactionBuilder strTrans, 25, g_str25                                            'References
    TransactionBuilder strTrans, 3056, g_str3056                                        'P.O. Number
    TransactionBuilder strTrans, 3057, g_str3057                                        'Invoice Number
    TransactionBuilder strTrans, 38, g_str38                                            'Department Notes
    TransactionBuilder strTrans, 537, g_str537                          'Thermal Label prt UNC/File Path
    If g_str1282 <> "L" Then
        TransactionBuilder strTrans, 187, g_str187                      'Thermal Label Type
    End If
    TransactionBuilder strTrans, 1282, g_str1282                        'Printer Type Indicator
    TransactionBuilder strTrans, 10, g_str10                            'Acct Number
    'Add flag and Shipper Country for return label
    TransactionBuilder strTrans, 2382, "2"                              'Create Ground Return label
    TransactionBuilder strTrans, 117, "US"                              'Shipper Country
    TransactionBuilder strTrans, 99, ""                                 'End of Transaction
    
    BuildReturnLabel = strTrans

    Exit Function
EH:
     MsgBox Err.Description, vbCritical, g_strErrorLocation

End Function
'---------------------------------------------------------------------------------------
' Module    : BuildRateTrans
' DateTime  : 6/11/2004
' Author    : Chris Elwell
' Purpose   : Builds and returns the transaction string for Rating a shipment from the
'             Ship form.
'---------------------------------------------------------------------------------------
'
Public Function BuildRateTrans() As String
    Dim strTrans As String
    Dim i As Integer
    Dim rsMPS As New ADODB.Recordset
    Dim strQuery As String
    
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildRateTrans"
    
    'Get MPS fields
    strQuery = "SELECT * FROM MPS WHERE f1 = " & SingleQuotes(g_str1)
    rsMPS.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    
    'Build the FXRS transaction
    strTrans = ""
    TransactionBuilder strTrans, 0, "020"                           'Transaction type
    TransactionBuilder strTrans, 1, g_str1                          'Transaction ID
    TransactionBuilder strTrans, 8, g_str8                          'Shipper State
    TransactionBuilder strTrans, 9, g_str9                          'Shipper Zip
    TransactionBuilder strTrans, 10, g_str10                        'Acct Number
    TransactionBuilder strTrans, 498, g_str498                      'Meter
    TransactionBuilder strTrans, 16, g_str16                        'Recipient State
    TransactionBuilder strTrans, 17, g_str17                        'Recipient Zip
    
    'Rate duplicate pkgs
    If Val(g_str116) > 1 And frmShip.chkDuplicate = 1 Then
        For i = 1 To CInt(g_str116)
            TransactionBuilder strTrans, "1670-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(g_str1670))          'Weight
        Next
        TransactionBuilder strTrans, 116, g_str116                        '# pkgs
    'Rate MPS
    ElseIf Val(g_str116) > 1 And rsMPS.RecordCount > 0 Then
        
        i = 1
        
        Do Until rsMPS.EOF
            TransactionBuilder strTrans, "1670-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsMPS!g_str1670))          'Weight
            TransactionBuilder strTrans, "57-" & Trim(Str(i)), rsMPS!g_str57 & ""          'DIM
            TransactionBuilder strTrans, "58-" & Trim(Str(i)), rsMPS!g_str58 & ""          'DIM
            TransactionBuilder strTrans, "59-" & Trim(Str(i)), rsMPS!g_str59 & ""          'DIM
            
            'Total Declared Value
            g_str26 = Str(Val(g_str26) + Val(rsMPS!g_str26 & ""))
                
            i = i + 1
            rsMPS.MoveNext
        Loop
        TransactionBuilder strTrans, 116, g_str116                        '# pkgs
    'Single piece and Intl Non-MPS rate
    Else
        'Add # pkgs for Intl when not using MPS
        If g_str117 = "US" And g_str50 <> "US" Then
            TransactionBuilder strTrans, 116, g_str116                        '# pkgs
        End If
        TransactionBuilder strTrans, 1670, RemoveSpecial(ImpliedDecimal(g_str1670))                'Weight
        TransactionBuilder strTrans, 57, g_str57                        'DIM H
        TransactionBuilder strTrans, 58, g_str58                        'DIM W
        TransactionBuilder strTrans, 59, g_str59                        'DIM L
    End If
    TransactionBuilder strTrans, 26, Trim(Str(CLng(Val(g_str26))))     'Declared Value
    TransactionBuilder strTrans, 23, g_str23                        'Pay Type
    'Send $1 for COD Amount if COD is selected.
    If g_str27 = "Y" Then
        TransactionBuilder strTrans, 27, g_str27                    'COD Flag
        TransactionBuilder strTrans, 53, "100"                      'COD Amount
    End If
    TransactionBuilder strTrans, 50, g_str50                        'Country - 2 character code
    TransactionBuilder strTrans, 75, g_str75                        'Weight Type
    TransactionBuilder strTrans, 440, g_str440                      'Residential flag
    TransactionBuilder strTrans, 1090, g_str1090                    'Currency type
    TransactionBuilder strTrans, 1234, "1"                          'Rate Flag
    TransactionBuilder strTrans, 1266, g_str1266                    'Sat Del Flag
    TransactionBuilder strTrans, 1273, g_str1273                    'Packaging Type
    TransactionBuilder strTrans, 1958, "BOX"                                            'FXRS0760 new Packaging Type
    TransactionBuilder strTrans, 1274, g_str1274                    'Service Type
    TransactionBuilder strTrans, 3008, g_str3008                    'Auto POD
    TransactionBuilder strTrans, 3009, g_str3009                    'AOD
    TransactionBuilder strTrans, 3018, g_str3018                    'Non-Standard Packaging
    TransactionBuilder strTrans, 3019, g_str3019                    'FHD Sig Svc
    TransactionBuilder strTrans, 3020, g_str3020                    'FHD Special SVCs
    TransactionBuilder strTrans, 99, ""                             'End of Transaction

    BuildRateTrans = strTrans

Release:

    If rsMPS.State = adStateOpen Then rsMPS.Close
    Set rsMPS = Nothing
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation
    Resume Release
    
End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildCloseTrans
' DateTime  : 12/17/2003
' Purpose   : Sends a Close transaction to FXRS
'---------------------------------------------------------------------------------------
'
Public Function BuildCloseTrans(ByVal strMeterNum As String, Optional ByVal strCloseType As String) As String
    Dim strTrans As String
    
    On Error GoTo EH
    g_strErrorLocation = "modMain:BuildCloseTrans"
    
    strTrans = ""
    TransactionBuilder strTrans, 0, "007"               'Transaction type
    TransactionBuilder strTrans, 1, "Close"             'Transaction ID
    TransactionBuilder strTrans, 498, strMeterNum       'Meter Number
    If strCloseType <> "" Then
        TransactionBuilder strTrans, 3025, strCloseType     'Close Type
    End If
    TransactionBuilder strTrans, 99, ""                 'End of Transaction
    
    BuildCloseTrans = strTrans
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation

End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildVersionCaptureTrans
' DateTime  : 11/11/2004
' Purpose   : This builds a Version Capture 070 transaction required for CSPs.
'---------------------------------------------------------------------------------------
'
Public Function BuildVersionCaptureTrans() As String
    Dim strTrans As String
    
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildVersionCaptureTrans"
    
    strTrans = ""
    TransactionBuilder strTrans, 0, "070"               'Transaction type
    TransactionBuilder strTrans, 1, "VersionCapture"    'Transaction ID
    TransactionBuilder strTrans, 498, ""                'Meter Number
    TransactionBuilder strTrans, 556, "3"               'Process Request Code
    TransactionBuilder strTrans, 9744, "NCNC"           'Client Product Name
    TransactionBuilder strTrans, 9746, "0300"           'Client Product Version
    TransactionBuilder strTrans, 99, ""                 'End of Transaction
    
    BuildVersionCaptureTrans = strTrans
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation

End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildIPDCreateTrans
' DateTime  : 3/17/2005
' Purpose   : Builds an IPD MAWB Transaction
'---------------------------------------------------------------------------------------
'
Public Function BuildIPDCreateTrans() As String
    Dim strTrans As String
    
    On Error GoTo EH
    g_strErrorLocation = "modMain:BuildCloseTrans"
    
    strTrans = ""
        
    TransactionBuilder strTrans, 0, "020"                   'Trans type
    TransactionBuilder strTrans, 1, "IPD MAWB CREATE"       'TransID
    TransactionBuilder strTrans, 23, g_str23                'Bill-To Type
    TransactionBuilder strTrans, 20, g_str20                'Bill-To Acct#
    TransactionBuilder strTrans, 50, g_str50                'Recip Country
    TransactionBuilder strTrans, 68, g_str68                'Currency Type
    TransactionBuilder strTrans, 70, g_str70                'Duty/Tax Pay Type
    TransactionBuilder strTrans, 71, g_str71                'Duty/Tax Acct#
    TransactionBuilder strTrans, 72, g_str72                'Terms of Sale
    TransactionBuilder strTrans, 74, g_str74                'Country of Ultimate Dest
    TransactionBuilder strTrans, 75, g_str75                'Weight type
    If g_str113 = "Y" Then
        TransactionBuilder strTrans, 113, g_str113          'CI Flag
    Else
        TransactionBuilder strTrans, 113, "N"               'CI Flag
    End If
    TransactionBuilder strTrans, 498, frmSetup.f498         'Meter #
    TransactionBuilder strTrans, 541, "YNNNNNNNN"           'Open Ship Flag
    TransactionBuilder strTrans, 1274, "18"                 'Service Type
    TransactionBuilder strTrans, 1297, g_str1297            'Customer Inv #
    TransactionBuilder strTrans, 1355, g_str1355            'IOR Facility Code
    TransactionBuilder strTrans, 1349, g_str1349            'AES Filing Status
    TransactionBuilder strTrans, 1358, g_str1358            'ITN/FTSR
    If g_str1592 = "Y" And g_str113 <> "Y" Then
        TransactionBuilder strTrans, 1592, "Y"              'Override Customs Val Flag
    End If
    
    TransactionBuilder strTrans, 99, ""                     'End of Transaction
    
    BuildIPDCreateTrans = strTrans
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation
End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildIPDShipTrans
' DateTime  : 10/26/2004
' Purpose   : Builds an IPD CRN Add Transaction
'---------------------------------------------------------------------------------------
'
Public Function BuildIPDShipTrans(ByVal strOrderNum As String) As String
    Dim strTrans As String
    Dim strQuery As String
    Dim rsCommodity As New ADODB.Recordset
    Dim i As Integer
    
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildIPDShipTrans"
    
    strQuery = "SELECT * FROM IntlCommodities WHERE f1 = '" & strOrderNum & "'"
    rsCommodity.Open strQuery, g_connFSMSClient, adOpenStatic, adLockOptimistic
    
    'Build the common fields
    strTrans = BuildCommonFlds
    
    TransactionBuilder strTrans, 26, Trim(Str(CLng(Val(g_str26))))       'Carriage Value
    TransactionBuilder strTrans, 57, g_str57                'DIM H
    TransactionBuilder strTrans, 58, g_str58                'DIM W
    TransactionBuilder strTrans, 59, g_str59                'DIM L
    TransactionBuilder strTrans, 1116, g_str1116            'DIM Units
    
    'Build the Intl MPS fields
    TransactionBuilder strTrans, 1358, g_str1358            'ITN/FTSR
    TransactionBuilder strTrans, 413, g_str413              'NAFTA Flag
    TransactionBuilder strTrans, 74, g_str74                'Country of Ultimate Dest
    TransactionBuilder strTrans, 75, g_str75                'Weight type
    TransactionBuilder strTrans, 72, "1"                    'Terms of Sale
    
    'Loop through commodities
    i = 1
    g_str119 = "0"
    Do While Not rsCommodity.EOF
        TransactionBuilder strTrans, "77-" & Trim(Str(i)), RemoveSpecial(rsCommodity("g_str77")) & ""           'Terms of Sale
        TransactionBuilder strTrans, "79-" & Trim(Str(i)), rsCommodity("g_str79") & ""                          'Description
        TransactionBuilder strTrans, "80-" & Trim(Str(i)), rsCommodity("g_str80") & ""                          'Country of Manu
        TransactionBuilder strTrans, "81-" & Trim(Str(i)), rsCommodity("g_str81") & ""                          'Harmonized Code
        TransactionBuilder strTrans, "82-" & Trim(Str(i)), rsCommodity("g_str82") & ""                          'Quantity
        TransactionBuilder strTrans, "83-" & Trim(Str(i)), rsCommodity("g_str83") & ""                          'Export license #
        TransactionBuilder strTrans, "84-" & Trim(Str(i)), Format(rsCommodity("g_str84"), "YYYYMMDD") & ""      'Export license Exp Date
        TransactionBuilder strTrans, "120-" & Trim(Str(i)), rsCommodity("g_str120") & ""                        'Marks and Numbers, 2005-03-29, JFW
        TransactionBuilder strTrans, "414-" & Trim(Str(i)), rsCommodity("g_str414") & ""                        'Unit of Measure
        TransactionBuilder strTrans, "1030-" & Trim(Str(i)), RemoveSpecial(ImpliedDecimal(rsCommodity("g_str1030"), 6)) & ""       'Commodity Unit Value
        TransactionBuilder strTrans, "1275-" & Trim(Str(i)), rsCommodity("g_str1275") & ""                        'Part Number, 2005-03-29, JFW
        'Add the Customs values of the individual commodities for a total
        g_str119 = Str(Val(g_str119) + Val(rsCommodity("g_str119"))) & ""
        i = i + 1
        rsCommodity.MoveNext
    Loop
    TransactionBuilder strTrans, 119, RemoveSpecial(ImpliedDecimal(g_str119))   'Total Customs value of shipment
    TransactionBuilder strTrans, 541, "NNNYNNNNN"                               'Open Ship Flags
    TransactionBuilder strTrans, 1355, g_str1355                                'IOR Facility Code
    
    TransactionBuilder strTrans, 99, ""                             'End of Transaction
    
    BuildIPDShipTrans = strTrans

Release:
    If rsCommodity.State = adStateOpen Then
        rsCommodity.Close
    End If
    Set rsCommodity = Nothing
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation
    Resume Release
    
End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildIPDConfirmTrans
' DateTime  : 3/17/2005
' Purpose   : Builds an IPD Confirm Transaction
'---------------------------------------------------------------------------------------
'
Public Function BuildIPDConfirmTrans() As String
    Dim strTrans As String
    
    On Error GoTo EH
    g_strErrorLocation = "modMain:BuildIPDConfirmTrans"
    
    strTrans = ""
    With frmIPD
        
        TransactionBuilder strTrans, 0, "020"                   'Trans type
        TransactionBuilder strTrans, 1, "IPD MAWB CONFRM" & .grdIPD.Columns(4)       'TransID
        TransactionBuilder strTrans, 50, .grdIPD.Columns(3)     'Recip Country
        TransactionBuilder strTrans, 498, frmSetup.f498         'Meter #
        TransactionBuilder strTrans, 541, "NNNNNYNNY"           'Open Ship Flag
        TransactionBuilder strTrans, 1274, "18"                 'Service Type
        TransactionBuilder strTrans, 1297, g_str1297            'Customer Inv #
        TransactionBuilder strTrans, 1355, .grdIPD.Columns(0)   'IOR Facility Code
        TransactionBuilder strTrans, 1358, g_str1358            'ITN/FTSR
        TransactionBuilder strTrans, 187, g_str187              'Label Type
        TransactionBuilder strTrans, 537, g_str537              'Thermal/Laser Label prt UNC/File Path
        
        'Don't send field 1282 if label type is laser (DIB)
        If g_str187 <> "DIB" And g_str187 <> "PNG" Then
            TransactionBuilder strTrans, 1282, g_str1282                    'Printer Type Indicator
        End If
    End With
    If g_str1592 = "Y" Then
        TransactionBuilder strTrans, 119, RemoveSpecial(ImpliedDecimal(g_str119))   'Total Customs value of shipment
        TransactionBuilder strTrans, 79, g_str79                          'Label Type
    End If
    
    
    TransactionBuilder strTrans, 99, ""                 'End of Transaction
    
    BuildIPDConfirmTrans = strTrans
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation
End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildIPDDeleteTrans
' DateTime  : 10/26/2004
' Purpose   : Builds an IPD Delete Shipment Transaction
'---------------------------------------------------------------------------------------
'
Public Function BuildIPDDeleteTrans() As String
    Dim strTrans As String
    
    On Error GoTo EH
    g_strErrorLocation = "modMain:BuildIPDDeleteTrans"
    
    strTrans = ""
    With frmIPD
        
        TransactionBuilder strTrans, 0, "020"                                   'Trans type
        TransactionBuilder strTrans, 1, "IPD MAWB DELETE" & .grdIPD.Columns(4)  'TransID
        TransactionBuilder strTrans, 29, .grdIPD.Columns(4)                     'MAWB Trk#
        TransactionBuilder strTrans, 50, .grdIPD.Columns(3)     'Recip Country
        TransactionBuilder strTrans, 498, frmSetup.f498         'Meter #
        TransactionBuilder strTrans, 541, "NNNNNNNYN"           'Open Ship Flag
        TransactionBuilder strTrans, 1274, "18"                 'Service Type
        TransactionBuilder strTrans, 1355, .grdIPD.Columns(0)   'IOR Facility Code
    
    End With
    
    TransactionBuilder strTrans, 99, ""                 'End of Transaction
    
    BuildIPDDeleteTrans = strTrans
    
    Exit Function
EH:
    MsgBox Err.Description, vbCritical, g_strErrorLocation
End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildDeleteTrans
' DateTime  : 2/18/2004
' Purpose   : Builds/returns a Delete transaction
'---------------------------------------------------------------------------------------
'
Public Function BuildDeleteTrans(ByVal strTrackNum As String) As String
    Dim strTrans As String
    
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildDeleteTrans"
    
    'Save the trk# to global var
    g_str29 = strTrackNum
    
    strTrans = ""
    TransactionBuilder strTrans, 0, "023"                   'Transaction type
    TransactionBuilder strTrans, 1, "Delete"                'Transaction ID
    TransactionBuilder strTrans, 29, g_str29                'Tracking #
    TransactionBuilder strTrans, 10, g_str10                'Acct Number
    TransactionBuilder strTrans, 99, ""                     'End of Transaction
    
    BuildDeleteTrans = strTrans
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, g_strErrorLocation

End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildCRNDeleteTrans
' DateTime  : 11/1/2004
' Purpose   : Deletes a trk#
'---------------------------------------------------------------------------------------
'
Public Function BuildCRNDeleteTrans(ByVal strTrackNum As String, ByVal strIOR As String, ByVal strCountry As String) As String
    Dim strTrans As String
    
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildCRNDeleteTrans"
    
    'Save the trk# to global var
    g_str29 = strTrackNum
    
    'Set IPD flag to True
    g_blnIPD = True
    
    strTrans = ""
    TransactionBuilder strTrans, 0, "020"                   'Transaction type
    TransactionBuilder strTrans, 1, "IPD CRN DELETE "       'Transaction ID
    TransactionBuilder strTrans, 29, g_str29                'Tracking #
    TransactionBuilder strTrans, 50, strCountry             'Country Code
    TransactionBuilder strTrans, 498, g_str498              'Meter #
    TransactionBuilder strTrans, 541, "NNNNNNYNN"           'Open Ship Flags
    TransactionBuilder strTrans, 1273, "18"                 'Tracking #
    TransactionBuilder strTrans, 1355, strIOR               'Acct Number
    TransactionBuilder strTrans, 99, ""                     'End of Transaction
    
    BuildCRNDeleteTrans = strTrans
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, g_strErrorLocation

End Function
'---------------------------------------------------------------------------------------
' Procedure : BuildLabelRepintTrans
' DateTime  : 11/3/2004
' Purpose   : Reprints a label
'---------------------------------------------------------------------------------------
'
Public Function BuildLabelReprintTrans(ByVal strTrackNum As String) As String
    Dim strTrans As String
    
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:BuildLabelReprintTrans"
    
    strTrans = ""
    TransactionBuilder strTrans, 0, "095"                   'Transaction type
    TransactionBuilder strTrans, 1, "Label Reprint"         'Transaction ID
    TransactionBuilder strTrans, 29, strTrackNum            'Tracking #
    TransactionBuilder strTrans, 537, frmSetup.f537         'Open Ship Flags
    TransactionBuilder strTrans, 99, ""                     'End of Transaction
    
    BuildLabelReprintTrans = strTrans
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, g_strErrorLocation

End Function
'---------------------------------------------------------------------------------------
' Procedure : SendData
' DateTime  : 2/18/2004
' Purpose   : Sends the strTrans passed to FXRS
'---------------------------------------------------------------------------------------
'
Public Sub SendData(ByVal strTrans As String)
    
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions:SendData"
    
    Debug.Print Now, "modFXRSTransations.SendData"
    Debug.Print strTrans
    
    'Send the transaction for each pkg.
    frmShip.wscFXRS.SendData strTrans

    Exit Sub
EH:
     MsgBox Err.Description, vbCritical, g_strErrorLocation
End Sub
'---------------------------------------------------------------------------------------
' Procedure : BuildTrkNumRequest
' DateTime  : 3/2/2005
' Purpose   : FXRS Tracking # request
'---------------------------------------------------------------------------------------
'
Public Function BuildTrkNumRequest(ByVal strOrderID As String, ByVal strType As String) As String
    
    Dim strTrans As String
    
    On Error GoTo EH
    g_strErrorLocation = "modFXRSTransactions.TrkNumRequest"
    
    TransactionBuilder strTrans, 0, "004"                   'Transaction type
    TransactionBuilder strTrans, 1, strOrderID              'Transaction ID
    TransactionBuilder strTrans, 498, g_str498              'Acct Number
    TransactionBuilder strTrans, 499, strType               'Trk# Type
    TransactionBuilder strTrans, 99, ""                     'End of Transaction
    
    BuildTrkNumRequest = strTrans
    
    Exit Function
EH:
     MsgBox Err.Description, vbCritical, g_strErrorLocation

End Function

